package com.zhentao.controller;

import com.zhentao.common.Result;
import com.zhentao.pojo.Banner;
import com.zhentao.service.IndexPublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Index")
@CrossOrigin(origins = "*", maxAge = 3600)
public class IndexPublicController {
    @Autowired
    private IndexPublicService indexPublicService;

    /**
     * 统一获取轮播图列表（支持位置、类型、状态筛选）
     * @param position 位置：0顶部轮播，1导航栏下方，null表示不限制
     * @param bannerType 类型：1活动，2超值特惠套餐，null表示不限制
     * @param status 状态：0下线，1上线，null表示不限制
     * @return 轮播图列表
     */
    @GetMapping("/banners/unified")
    public Result<List<Banner>> getBannersUnified(
            @RequestParam(value = "position", required = false) Integer position,
            @RequestParam(value = "bannerType", required = false) Integer bannerType,
            @RequestParam(value = "status", required = false) Integer status) {
        try {
            List<Banner> banners = indexPublicService.listIndexBanners(position, bannerType, status);
            return Result.success("获取轮播图成功", banners);
        } catch (Exception e) {
            return Result.error("获取轮播图失败: " + e.getMessage());
        }
    }
}